package com.huakang.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;


import com.huakang.entity.Medbuy;
import com.huakang.service.MedbuyService;

import com.huakang.utils.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("medbuy")
public class MedbuyController {

    @Autowired
    private MedbuyService medbuyService;

    @GetMapping("/findAll")
    public ResultVo medbuyList(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
       List<Medbuy> medbuyList =  medbuyService.findAll();
        PageInfo<Medbuy> pageInfo = new PageInfo<>(medbuyList);
       return ResultVo.success("显示成功",pageInfo);
    }

    @PostMapping("/medbuyadd")
    public ResultVo medbuyadd(@RequestBody Medbuy medbuy){
        boolean flag = medbuyService.medbuyadd(medbuy);
        if(flag){
            return ResultVo.success("成功");
        }
        return ResultVo.fail("失败");
    }

    @PostMapping("buySearch")
    public ResultVo buySearch(@RequestBody Medbuy medbuy,@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "5") Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Medbuy> medbuyList =  medbuyService.buySearch(medbuy);
        PageInfo<Medbuy> pageInfo = new PageInfo<>(medbuyList);
        return ResultVo.success("成功",pageInfo);
    }
}


